package com.ruoyi.teacher.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teacher.domain.TeacherReport;
import com.ruoyi.teacher.service.ITeacherReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 老师日报Controller
 *
 * @author clid
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/report")
public class TeacherReportController extends BaseController {
    @Autowired
    private ITeacherReportService teacherReportService;

    /**
     * 定时统计异常
     *
     * @return {@link R}<{@link Void}>
     */
    @GetMapping("/timeNoticeTeacherReport")
    public R<Void> timeNoticeTeacherReport() {
        teacherReportService.timeNoticeTeacherReport();
        return R.ok();
    }




    /**
     * 定时统计异常
     *
     * @return {@link R}<{@link Void}>
     */
    @GetMapping("/abnormalTimingStatistics")
    public R<Void> abnormalTimingStatistics() {

        teacherReportService.abnormalTimingStatistics();
        return R.ok();
    }

    /**
     * 查询老师日报列表
     */
    @RequiresPermissions("teacher:report:list")
    @GetMapping("/list")
    public TableDataInfo list(TeacherReport teacherReport) {
        startPage();
        List<TeacherReport> list = teacherReportService.selectTeacherReportList(teacherReport);
        return getDataTable(list);
    }

    /**
     * 导出老师日报列表
     */
    @RequiresPermissions("teacher:report:export")
    @Log(title = "老师日报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherReport teacherReport) {
        List<TeacherReport> list = teacherReportService.selectTeacherReportList(teacherReport);
        ExcelUtil<TeacherReport> util = new ExcelUtil<TeacherReport>(TeacherReport.class);
        util.exportExcel(response, list, "老师日报数据");
    }

    /**
     * 获取老师日报详细信息
     */
    @RequiresPermissions("teacher:report:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teacherReportService.selectTeacherReportById(id));
    }

    /**
     * 新增老师日报
     */
    @RequiresPermissions("teacher:report:add")
    @Log(title = "老师日报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherReport teacherReport) {
        return toAjax(teacherReportService.insertTeacherReport(teacherReport));
    }

    /**
     * 修改老师日报
     */
    @RequiresPermissions("teacher:report:edit")
    @Log(title = "老师日报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherReport teacherReport) {
        return toAjax(teacherReportService.updateTeacherReport(teacherReport));
    }

    /**
     * 删除老师日报
     */
    @RequiresPermissions("teacher:report:remove")
    @Log(title = "老师日报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teacherReportService.deleteTeacherReportByIds(ids));
    }
}
